//---------------------------------------------------------------------------

#ifndef DPCnsCustosH
#define DPCnsCustosH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "DialPad.h"
#include "PHDS.h"
#include <ExtCtrls.hpp>
#include "PHCombo.h"
#include "PHEdit.h"
#include "PHLabel.h"
#include "PHSpdBut.h"
#include <Buttons.hpp>
#include "PHGridEd.h"
#include <Grids.hpp>
//---------------------------------------------------------------------------
class TDPCnsCustos1 : public TDiPad
{
__published:	// IDE-managed Components
    TBitBtn *BitBtn1;
    PHDataSource *DSPesosTotal;
    PHLabel *PHLabel5;
    PHComboBox *PHComboBox1;
    PHLabel *PHLabel6;
    PHComboBox *PHComboBox2;
    PHLabel *PHLabel1;
    PHEdit *PHEdit1;
    PHLabel *PHLabel2;
    PHEdit *PHEdit2;
    PHSpeedButton *PHSpeedButton1;
    PHEdit *PHEdit3;
    TBitBtn *BitBtn2;
    TBitBtn *BitBtn3;
        PHLabel *PHLabel3;
        PHEdit *PHEdit4;
        PHGridEdit *Grid;
        TLabel *Label1;
        TLabel *Label2;
        PHDataSource *DSSoma;
    void __fastcall BitBtn1Click(TObject *Sender);
    void __fastcall PHComboBox1Change(TObject *Sender);
    void __fastcall DSPesosTotalAfterOpen(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall PHComboBox2Change(TObject *Sender);
    void __fastcall BitBtn3Click(TObject *Sender);
        void __fastcall GridDrawGridCell(int Row, int Col,
          TColor &CorTexto, TColor &CorFundo, bool &AplicarCoresSelecao,
          PHDataSource *PHDS, AnsiString &Conteudo);
        void __fastcall BitBtn2Click(TObject *Sender);
        void __fastcall GridDblClick(TObject *Sender);
        void __fastcall GridKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall FormDestroy(TObject *Sender);
 void __fastcall PHEdit1Change(TObject *Sender);
 void __fastcall PHEdit4Change(TObject *Sender);

private:	// User declarations

    bool ProcessaSistema[5];
    double CustosFixos[13];
    double CustosVariaveis[13];
    double CustoFixoIndividual[13];
    double ValorDoPeso[13];
    unsigned long TotalDePesos[13];
    TStringList *ClientesMes[13];
    int ColunaDiferenca, ColunaCusto, ColunaFaturado;
    AnsiString MesFinal;

    void __fastcall Ordena(AnsiString Campo);
    AnsiString __fastcall RetornaNomeCampo(int Sistema, int Nivel, int Elemento);
    AnsiString __fastcall RetornaNomeSistema(int Sistema);
    void __fastcall CarregaCustos(int MesInicial, int MesFinal);
    void __fastcall LimpaTabelasRetorno(void);
    void __fastcall ProcessaConsulta(TObject *Sender);
    void __fastcall CriaMatrizNomeCampos();
    void __fastcall CalculaTotalEvolucao(void);
    bool __fastcall ChamaSistema(int Sistema, AnsiString Diretorio);
    void __fastcall TotalizaPesos(int Sistema,
                                  PHDataSource *DSPesos,
                                  PHDataSource *DSClientes);
    void __fastcall GeraConsulta(int Sistema,
                                 PHDataSource *DSGeracao,
                                 PHDataSource *DSPesosTotais,
                                 PHDataSource *DSPesos,
                                 PHDataSource *DSClientes);
    void __fastcall AjustaColunasGrid(void);
    AnsiString __fastcall InverteOrdem(double Valor);
    void __fastcall Combos(boolean Habilita);

    AnsiString NomesAT[1][2];
    AnsiString NomesDP[2][13];
    AnsiString NomesEF[4][14];
    AnsiString NomesSC[2][3];

    struct PESOST * P ;

public:		// User declarations
    __fastcall TDPCnsCustos1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TDPCnsCustos1 *DPCnsCustos1;
//---------------------------------------------------------------------------
#endif
